<?php
namespace App\Http\Controllers\Client\Common;

use App\Http\Controllers\ClientController;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class CheckMessageController extends ClientController
{

    public function index()
    {
        /**
         * 验证手机号
         */

        $all = $this->all;

        if(empty($all['code'])){
            return $this->setReturnJson(-1,'未传手机号');
        }

        if ($all['code'] != Redis::hget('message_code_' . $this->we_id, 'code')) {
            return $this->setReturnJson(-1, '验证码错误');
        } else {
            $phone = Redis::hget('message_code_' . $this->we_id, 'phone');
            // 如果验证了新的手机号，保存手机号
            if($phone){
                DB::table('lottery_users')->where('we_id',$this->we_id)->update(['phone'=>$phone]);
            }
            // 删除验证码信息
            Redis::del('message_code_' . $this->we_id);
            return $this->setReturnJson(0,'success');
        }

    }

}
